第三十三屆 ITSA 月賽 ,第一題,
參考解法
http://blog.xuite.net/isdp2008am/wretch/123046347-%E6%8E%92%E9%9A%8A%E7%9C%8B%E9%9B%BB%E5%BD%B1%E7%9A%84%E5%95%8F%E9%A1%8C
我們團隊(寫Code是一種表演的藝術)的俊諳解出
需利用到大數運算
程式碼:
#include <iostream>
using namespace std;
class bigNumber
{
#define NUM_SIZE 32
int *num;
int numSize;
public:
bigNumber();
bigNumber operator+(bigNumber b);
void setNum(int *v);
void print();
};
bigNumber::bigNumber():numSize(NUM_SIZE), num(new int[NUM_SIZE])
{
for(int i = 0; i < numSize; ++i)num[i] = 0;
}
bigNumber bigNumber::operator+(bigNumber b)
{
int i;
bigNumber c;
for(i = 0; i < numSize; ++i)
{
c.num[i] = num[i] + b.num[i];
}
for(i = 0; i < numSize - 1; ++i)
{
c.num[i + 1] += c.num[i] / 10;
c.num[i] %= 10;
}
return c;
}
void bigNumber::setNum(int *v)
{
for(int i = 0; i < numSize; ++i)num[i] = v[i];
}
void bigNumber::print()
{
int i = numSize - 1;
while(i >= 0 && num[i] == 0) --i;
if(i < 0)cout << '0';
else for(; i >= 0; --i)cout << num[i];
}
int main()
{
char c;
int a, b;
int v[32] = {0};
bigNumber table[51][51];
v[0] = 1;
for(int i = 1; i < 51; ++i)
{
table[0][i].setNum(v);
}
for(int i = 1; i < 51; ++i)
{
for(int j = i; j < 51; ++j)
{
table[i][j] = table[i-1][j] + table[i][j-1];
}
}
while(cin >> a >> c >> b)
{
table[b][a].print();
cout << endl;
}
return 0;
}